import { onMounted, provide, ref } from 'vue'
import { getShiftTime } from '@/api/mesApi'

export default function () {
  const shiftCode = ref('--')
  const shiftDate = ref('--')
  const shiftDateTime = ref('--')

  provide('shiftCode', shiftCode)
  provide('shiftDate', shiftDate)
  function getCurrentDateFormatted() {
    const now = new Date();
    const year = now.getFullYear();
    const month = now.getMonth() + 1; // getMonth() 返回的月份是从0开始的
    const day = now.getDate();

    const formattedDate = `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
    
    return formattedDate;
  }
  const shiftTime = () => {
    getShiftTime({
      code:'ShiftTime'
    }).then(res => {
      shiftCode.value = res.data
      shiftDate.value = getCurrentDateFormatted()
      // shiftDateTime.value = res.data
    })
  }
  onMounted(() => {
    shiftTime()
    // setInterval(shiftTime, 3000)
  })
  return { shiftCode, shiftDate }
}
